
package me.zhengjie.modules.system.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.system.domain.PetCategories;
import me.zhengjie.modules.system.service.PetCategoriesService;
import me.zhengjie.modules.system.domain.vo.PetCategoriesQueryCriteria;
import lombok.RequiredArgsConstructor;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
* @author ck
* @date 2025-02-11
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "宠物类别管理管理")
@RequestMapping("/api/petCategories")
public class PetCategoriesController {

    private final PetCategoriesService petCategoriesService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('petCategories:list')")
    public void exportPetCategories(HttpServletResponse response, PetCategoriesQueryCriteria criteria) throws IOException {
        petCategoriesService.download(petCategoriesService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询宠物类别管理")
    @ApiOperation("查询宠物类别管理")
    @PreAuthorize("@el.check('petCategories:list')")
    public ResponseEntity<PageResult<PetCategories>> queryPetCategories(PetCategoriesQueryCriteria criteria, Page<Object> page){
        return new ResponseEntity<>(petCategoriesService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增宠物类别管理")
    @ApiOperation("新增宠物类别管理")
    @PreAuthorize("@el.check('petCategories:add')")
    public ResponseEntity<Object> createPetCategories(@Validated @RequestBody PetCategories resources){
        petCategoriesService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改宠物类别管理")
    @ApiOperation("修改宠物类别管理")
    @PreAuthorize("@el.check('petCategories:edit')")
    public ResponseEntity<Object> updatePetCategories(@Validated @RequestBody PetCategories resources){
        petCategoriesService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除宠物类别管理")
    @ApiOperation("删除宠物类别管理")
    @PreAuthorize("@el.check('petCategories:del')")
    public ResponseEntity<Object> deletePetCategories(@RequestBody List<Integer> ids) {
        petCategoriesService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}